<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>移交纪委数</title>
	<script th:src="@{/js/jquery/3.5.1/jquery.min.js}" ></script>
	<link th:href="@{/css/bootstrap-3.3.7-dist/css/bootstrap.min.css}" rel="stylesheet">
	
	
	<script th:src="@{/js/layui/2.5.7/layui/layui.js}" ></script>
	<link th:href="@{/js/layui/2.5.7/layui/css/layui.css}" rel="stylesheet">
	
	<link th:href="@{/css/common/common.css}" rel="stylesheet">
	
	<script th:src="@{/js/common/yUtil.js}" ></script>
	
	<script th:src="@{/js/My97DatePicker/WdatePicker.js}" ></script>
	
	<style type="text/css">

	</style>
</head>
<body>



	<div id="el" class="all">
		<div class="div_header">
		<!-- 
			<div class="row">
				<div class="col-md-3">
					<span>要件名称：</span>
					<input style="width: 120px;" type="text" v-model="queryParam.item_name">
					
					<button type="button" class="btn btn-primary " @click="queryList();">查询</button>
					<button type="button" class="btn btn-primary " @click="_resetQueryParam();">重置</button>
				</div>
			</div>
			 -->
			<div class="row">
				<div class="col-md-12" style="text-align: right;">
					<button type="button" class="btn btn-primary " onclick="toAdd();">增加</button>
				</div>
			</div>
		</div>
		<div class="div_main">
			<div id="div_content" class="main_div">
				<div id="mainList" style="width: 100%;">
					
				</div>
			</div>
		</div>
		
		
		
		
	</div>

	<div id="addDiv" style="width: 350px; height: 250px;padding: 15px;display: none;">
		<div style="display: inline-block;">
		</div>
		
		<br/>
		<br/>
		
		<div style="width: 100px; display: inline-block;"><span>年份：</span></div>
		<div style="display: inline-block;">
			<input id="year_id" style="width: 120px;" autocomplete="off"
				onclick="WdatePicker({dateFmt:'yyyy'})"
				type="text" class="Wdate _addParam">
			
		</div>
		<br/>
		<br/>
		<div style="width: 100px; display: inline-block;"><span>轮次：</span></div>
		<div style="display: inline-block;">
			<input id="turn_desc" style="width: 120px;" type="text" class="_addParam">
		</div>
		<br/>
		<br/>
		<div style="width: 100px; display: inline-block;"><span>数量：</span></div>
		<div style="display: inline-block;">
			<input id="num" style="width: 120px;" type="text" class="_addParam">
		</div>
		<br/>
		<br/>
		<div style="text-align: right; padding-right: 15px;">
			<button type="button" class="btn btn-primary " onclick="doAdd();">保存</button>
			<button type="button" class="btn btn-primary " onclick="closeAll();">取消</button> 
		</div>
	</div>
	
	<div id="updateDiv" style="width: 350px; height: 250px;padding: 15px;display: none;">
		<div style="display: inline-block;">
			<input id="id" style="width: 120px;" type="hidden" class="_updateParam">
		</div>
		
		<div style="width: 100px; display: inline-block;"><span>年份：</span></div>
		<div style="display: inline-block;">
			<input id="year_id" style="width: 120px;" autocomplete="off"
				onclick="WdatePicker({dateFmt:'yyyy'})"
				type="text" class="Wdate _updateParam">
			
		</div>
		
		<br/>
		<br/>
		
		<div style="width: 100px; display: inline-block;"><span>轮次：</span></div>
		<div style="display: inline-block;">
			<input id="turn_desc" style="width: 120px;" type="text" class="_updateParam">
		</div>
		<br/>
		<br/>
		<div style="width: 100px; display: inline-block;"><span>数量：</span></div>
		<div style="display: inline-block;">
			<input id="num" style="width: 120px;" type="text" class="_updateParam">
		</div>
		<br/>
		<br/>
		<div style="text-align: right; padding-right: 15px;">
			<button type="button" class="btn btn-primary " onclick="updateYjjws();">修改</button>
			<button type="button" class="btn btn-primary " onclick="closeAll();">取消</button> 
		</div>
	</div>
	
</body>
<script type="text/javascript">
	
	$(function(){ 
		queryList();
		
		layui.use('layer', function(){
			var layer = layui.layer;
			window._layer = layer;
		});
	});
	
	function closeAll(){
		_layer.closeAll();
	}
	
	function queryList(){
		var col1 = [ [

			{field:'year_id', width:'20%', title: '年份'}
			,{field:'turn_desc', width: '20%', title: '轮次'}
			,{field:'num', width: '20%', title: '数量'} 
			,{field:'num',width: '40%', title: '操作', templet:function(row){
			var html = "";
			html += "<a onclick=\"toUpdate('"+row.id+"');\">编辑</a>&nbsp;&nbsp;";
			html += "<a onclick=\"deleteYjjws('"+row.id+"');\">删除</a>&nbsp;&nbsp;";
			return html;
			}}
					    ] ];
		
		layui.use('table', function(){
		  var table = layui.table;
		  window.myTable = table;
		  //var xh= $(window).height() -($("#projectList").height()+$("#mainList").offset().top-$(document).scrollTop());
		  var xh = 400;
		  
		  table.render({
		    elem: '#mainList'
		    ,method: "get"
		    ,url: '[[@{/}]]rest/txzldp/xsXc/queryYjjws'
		    ,cols: col1
		    ,done: function (res, curr, count) {
                window._date = res.data;
            }

		  });
	      
		});
		
	}
	
	function toAdd(){
		//console.log(_yutil);
		_yutil.cleanParam(jQuery("._addParam"));
		self.addIndex = _layer.open({
		  type: 1,
		  shade: false,
		  title: false, 
		  content: $('#addDiv')
		});
	}
	
	function toUpdate(id){
		var param;
		for(let i = 0; i < window._date.length; i++){
			if(window._date[i].id == id){
				param = window._date[i];
				break;
			}
		}
		jQuery("[id=id][class*=_updateParam]").val(param.id);
		//jQuery("[id=year_id][class*=_updateParam]").val(param.year_id);
		jQuery("[id=turn_desc][class*=_updateParam]").val(param.turn_desc);
		jQuery("[id=num][class*=_updateParam]").val(param.num);
		jQuery("[id=year_id][class*=_updateParam]").val(param.year_id);
		
		self.addIndex = _layer.open({
		  type: 1,
		  shade: false,
		  title: false, 
		  content: $('#updateDiv')
		});
	}
	
	function doAdd(){
		jQuery.ajax({
			url: '[[@{/}]]rest/txzldp/xsXc/insertYjjws',
			async: true,
			//dataType: 'json',
			contentType: "application/json",
			type: 'post',
			data: JSON.stringify(_yutil.queryParam(jQuery("._addParam"))),
			//data: _util._queryParam(jQuery("._addParam")),
			success: function(res){
				//console.log(res);
				if(res.code == -1){
					alert("该年已录入数据");
				}
				_layer.closeAll();
				queryList();
			}
		});
		
	}
	
	function updateYjjws(){
		jQuery.ajax({
			url: '[[@{/}]]rest/txzldp/xsXc/updateYjjws',
			async: true,
			//dataType: 'json',
			contentType: "application/json",
			type: 'post',
			data: JSON.stringify(_yutil.queryParam(jQuery("._updateParam"))),
			//data: _util._queryParam(jQuery("._addParam")),
			success: function(res){
				//console.log(res);
				_layer.closeAll();
				queryList();
			}
		});
		
	}
	
	function deleteYjjws(id){
		if(!confirm("是否删除？"))
			return;
		jQuery.ajax({
			url: '[[@{/}]]rest/txzldp/xsXc/deleteYjjws',
			async: true,
			//dataType: 'json',
			contentType: "application/json",
			type: 'post',
			data: JSON.stringify({id: id}),
			//data: _util._queryParam(jQuery("._addParam")),
			success: function(res){
				//console.log(res);
				queryList();
			}
		});
		
	}
	
</script>
</html>